<?php
/* SVN FILE: $Id: app_startup.php 50 2009-08-27 05:54:31Z phamshantuyet@gmail.com $ */
/**
*
* @author $Author: phamshantuyet@gmail.com $
* @version $Revision: 50 $
* @lastrevision $Date: 2009-08-27 12:54:31 +0700 (Thu, 27 Aug 2009) $
* @modifiedby $LastChangedBy: phamshantuyet@gmail.com $
* @lastmodified $LastChangedDate: 2009-08-27 12:54:31 +0700 (Thu, 27 Aug 2009) $
* @filesource $URL: https://ladybirdphp.googlecode.com/svn/trunk/website/ocm/app/app_startup.php $
*/

#include APP_DIR.'/vendors/quickcache/quickcache.php';


$map = explode( '_', $_GET['_request_uri']);
if( count( $map) == 2) { // neu co SEO & alias
	preg_match( '#[a-z0-9]+#', $map[1], $result);
	$map[1] = str_replace( '/-', '/', str_replace( $result[0], $URL_MAP[$result[0]], $map[1]));
	$_GET['_request_uri'] = str_replace( array( '.24h','/-','-'), array('','/','/'), $map[1]);
	$_GET['_request_uri'] = str_replace( $result[0], $URL_MAP[$result[0]], $_GET['_request_uri']);
	$_APP_PATH_INFO_ = explode( '/', $_GET['_request_uri']);
}
ob_start();
session_start();
error_reporting( E_ALL ^ E_NOTICE);

/**
 * dinh nghia ham bao loi rieng - neu ko co ham _myErrorHandler se su dung ham fw24h_myErrorHandler cua fw24h.
 * _myErrorHandler()
 * 
 * @param mixed $p_errno
 * @param mixed $p_errstr
 * @param mixed $p_errfile
 * @param mixed $p_errlile
 * @return
 */
function _myErrorHandler( $p_errno, $p_errstr, $p_errfile, $p_errlile) { 
	if( $p_errno == E_NOTICE  || $p_errno == E_STRICT) { // Notice - bo qua
		return true;
	}

	$GLOBALS['_FW24H_ERROR_'] = true;
	$GLOBALS['QUICKCACHE_ON'] = 0; // ko cache du lieu bi loi

	$f_error_msg = date( 'Y-m-d H:i:s')."; Err_Code: $p_errno; Err_Str: $p_errstr; Err_File: $p_errfile; Err_Line: $p_errlile\n";

	error_log( $f_error_msg, 3, APP_DIR.'/logs/runtime-errors.log');
	if( DISPLAY_ERROR) {
		echo $f_error_msg;
		echo '<PRE>';
		include APP_DIR.'/views/layouts/error.php';
	}else{
		// hanh dong sau khi co loi
		fw24h_url_redirect( ERROR_URL.'?ERROR_ID='.fw24h_base64_url_encode( fw24h_ErrRequest().'&ERR_MSG='.$f_error_msg));
	}
	
	// ---
	exit(0);
}

